Repository navigation
Return nil from Date#<=> for a NaN - #199
Merged
Merged
Conversation
thomasklemm
added a commit
to thomasklemm/lowrail
that referenced
this pull request
Nov 5, 2026
Move ruby-bench #569-#572 from Merged to Open (ready), drop the duplicate with_advisory_lock#150 entry, add ruby/date#199 and the closed ferrum#697, mark ransack#1795 and tzinfo#175 ready, refresh heads (#59614, #59668, ruby-bench#568, ruby/ruby#19681, tzinfo#171), add missing merge dates, and record the 2026-11-05 open counts. RA1 item synced to ready.
Contributor
$ ruby -r bigdecimal -e 'p(1 < Float::NAN); p(1 < BigDecimal("NaN"))'
false
false |
Contributor
Author
|
You're right, thanks. Integer and Float define their own |
thomasklemm
force-pushed
the
thomasklemm/cmp-nan
branch
from
November 14, 2026 11:33
f1d893f to
8a34d5a
Compare
thomasklemm
added a commit
to thomasklemm/lowrail
that referenced
this pull request
Nov 14, 2026
Date#<=> passed the result of ajd <=> other to rb_cmpint, which turns the nil that Rational#<=> returns for a NaN into an ArgumentError, so Date <=> Float::NAN raised and Date == Float::NAN raised with it. Return nil when ajd <=> other does, as Integer#<=> and Rational#<=> do, and keep normalizing other results to -1, 0 or 1.
Date#step, #upto and #downto passed the result of Date#<=> to FIX2INT, which expects a Fixnum; for nil it raises TypeError on 64-bit Linux and macOS and its behaviour depends on the build elsewhere. Use rb_cmpint, which raises ArgumentError for nil.
thomasklemm
force-pushed
the
thomasklemm/cmp-nan
branch
from
November 15, 2026 10:49
8a34d5a to
1c273d4
Compare
thomasklemm
added a commit
to thomasklemm/lowrail
that referenced
this pull request
Nov 15, 2026
Rebased VB1 (#59803), #59609, #59617, #59621, #59574, UG82 (#59675), ruby/date#199 and ruby/ruby #19681, #19659, #19492 onto their current bases; re-committed sqlite3-ruby#770 to rerun a musl Ractor flake. All six Rails PRs and #770 are green. cells-rails#75 is red from dependency drift on its master and was left alone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for maintaining date.
While testing Active Model's
changed?with random values, I found thatDate#<=>raisesArgumentErrorwhen the other value isFloat::NANorBigDecimal("NaN"), andDate#==raises with it, while1 <=> Float::NAN,Rational(1) <=> Float::NANandTime.now <=> Float::NANreturnnil.cmp_genpasses the result ofajd <=> othertorb_cmpint, which turns thenilfromRational#<=>into that exception.This returns
nilwhenajd <=> otherdoes and still normalizes other values to -1, 0 or 1.Date <=> NaNis nownilandDate == NaNisfalse, whileDate < NaNstill raisesArgumentError, asComparabledoes forTimeandRational. The second commit makes the comparisons instep,uptoanddowntoraiseArgumentErrorfor a limit thatDate#<=>can't compare, instead of passingniltoFIX2INT. The suite passes on Ruby 4.0.9 and master.